;;; mozremote-tests.el --- 

;; Copyright 2006 Lukas Loehrer
;;
;; Author: loehrerl [at] gmx [dot] net
;; Version: $Id: mozremote-tests.el,v 0.0 2006/08/08 14:59:16 luke Exp $
;; Keywords: 
;; X-URL: not distributed yet

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;;; Commentary:

;; 

;; Put this file into your load-path and the following into your ~/.emacs:
;;   (require 'mozremote-tests)

;;; Code:

(provide 'mozremote-tests)
(eval-when-compile
  (require 'cl))

(require 'mozremote)

(mozremote-log-event "Hello Event")

(mozremote-array-get 1 '(1 2 3))
(let ((test-list '(1 2 3 4 5)))
  (mozremote-array-set 2 "Hello" test-list)
  test-list)

(let ((test-dict '((hello . world) (foo . bar))))
  (mozremote-dictionary-set 'foo "This entry was changed" test-dict)
  (mozremote-dictionary-get 'foo test-dict))

(defun mozremote-tests-message (arg)
  (message "%s" arg))

(mozremote-call 'mozremote-show-result "TestService" "increment" 32 10)
(mozremote-call-sync "TestService" "increment" 32 10)

(mozremote-call 'mozremote-show-result "TestService" "echoArgs" 19)
(mozremote-call 'mozremote-show-result "TestService" "getSimpleObject")

(mozremote-call 'mozremote-show-result "NotExistingService" "increment" 32 10)
(mozremote-call-sync "NotExistingService" "increment" 32 10)

(setq a (mozremote-object-new "TestClass"))
(setq b (mozremote-object-new "TestClass"))
(mozremote-object-call-method-sync b "method1" 1 16)
(hash-table-count mozremote-object-obtable)
(mozremote-object-garbage-collect)
(setq a nil b nil)


(mozremote-object-call-method-sync a "method2")
(mozremote-object-call-method-sync a "method3" b)

(mozremote-call 'mozremote-show-result "Services" "listServices")



(mozremote-call (mozremote-insert-result) "TestService" "increment" 32 10)

(mozremote-call (mozremote-insert-result) "Services" "listServices")


;; Browsing tests
(setq my-window (mozremote-call-sync "Browsing" "getNewBrowserWindow"))
(setq my-window-2 (mozremote-call-sync "Browsing" "getNewBrowserWindow"))

(mozremote-object-call-method-sync my-window "loadURL" "http://blindcooltech.com")
(mozremote-object-call-method-sync my-window "loadURL" "http://homepage.hispeed.ch/loehrer/flite_alsa.html") 
(mozremote-object-call-method-sync my-window-2 "loadURL" "http://digg.com")

(mozremote-dictionary-get 'title (mozremote-object-call-method-sync my-window "getDocumentInfo"))
(mozremote-object-call-method-sync my-window "getIR")
(setq my-inspector (mozremote-object-call-method-sync my-window "createInspector"))
(mozremote-object-call-method-sync my-inspector "getDOMNodeInfo")
(mozremote-object-call-method-sync my-inspector "domNthChild" 0)


(defun mozremote-tests-browsing nil
  (let (( my-window (mozremote-call-sync "Browsing" "getNewBrowserWindow")))
	(sleep-for 5)
	(mozremote-object-call-method-sync my-window "loadURL" "http://emacspeak.sf.net")
	(sleep-for 5)
	(message (mozremote-dictionary-get 'title (mozremote-object-call-method-sync my-window "getDocumentInfo")))
	(mozremote-object-call-method-sync my-window "getIR")  ))

(mozremote-tests-browsing)

;;{{{Event handling tests

(mozremote-call-sync "Browsing" "enableEvent" "PageLoaded")

(defun mozremote-tests-page-load-handler (message)
  (let ((body (mozremote-dictionary-get 'args message)))
	(message "A page was loaded: %s"
			 (mozremote-dictionary-get 'title body))))

(mozremote-event-add-handler "Browsing" "PageLoaded" 'mozremote-tests-page-load-handler)

;;}}}

(mozremote-call (mozremote-insert-result) "JSEvaluation" "evaluate" "2+2;")
"4"


(mozremote-call (mozremote-insert-result) "JSEvaluation" "evaluate" "content.location = \"http://slashdot.org\";")
"about:blank"

"about:blank"

"about:blank"


(mozremote-call (mozremote-insert-result) "JSEvaluation" "evaluate" "repl.print(\"Title: \" + title)")





;;{{{  emacs local variables

;;; local variables:
;;; folded-file: t
;;; byte-compile-dynamic: t
;;; end:

;;}}}

;;; mozremote-tests.el ends here
